﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using EntityLibrary;
using BusinessLibary;

namespace Medicare
{
    public partial class FrmInhosRegisterNew : Form
    {
        #region 自定义变量
        private IMedicare.IMedicare medicare;
        private int retint = 0;

        private YBBZInfoFacade ybbzFacade;
        private string bzbm = string.Empty;//病种编码
        private string bzmc = string.Empty;//病种名称

        #endregion

        public FrmInhosRegisterNew()
        {
            InitializeComponent();

            medicare = IMedicare.IMedicareFactory.Instance.CreateIMedicare();//s
            ArrayList list = new ArrayList();
            retint = medicare.InitHisDLL(list);
            if (retint != 0)
            {
                MessageBox.Show("医保接口初始化失败，请检查医保网络！");
                return;
            }

        }

        private void cboRytj_Properties_QueryPopUp(object sender, CancelEventArgs e)
        {

        }

        private void cboRybq_Properties_QueryPopUp(object sender, CancelEventArgs e)
        {

        }

        #region 新增医保入院登记

        /// <summary>
        /// 新增医保入院登记
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnInhosReg_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        #endregion

        #region 编辑

        private void btnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }


        #endregion

        #region 保存信息
        /// <summary>
        /// 保存信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRegSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }


        #endregion

        #region 登记取消
        private void btnRegCancel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }


        #endregion

        #region 退出
        private void btnExit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }


        #endregion

        private void txtKh_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            //读卡或者无卡操作


        }

        private string GetPersonType(string code)
        {/*11	在职               
21	退休               
31	离休               
32	建国前老工人       
33	六等以上伤残军人   
80	未成年居民
81	一般居民
82	老年居民*/
            string codeName;
            switch (code)
            {
                case "11":
                    codeName = "在职";
                    break;
                case "21":
                    codeName = "退休";
                    break;
                case "31":
                    codeName = "离休";
                    break;
                case "32":
                    codeName = "建国前老工人";
                    break;
                case "33":
                    codeName = "六等以上伤残军人";
                    break;
                case "80":
                    codeName = "未成年居民";
                    break;
                case "81":
                    codeName = "一般居民";
                    break;
                case "82":
                    codeName = "老年居民";
                    break;
                default:
                    codeName = "未知";
                    break;
            }
            return codeName;
        }

        private void ShowPersonInfo()
        {
            DataSet paientInfo = new DataSet();
            ArrayList PrenoList = new ArrayList();
            retint = medicare.ReadCard(1, "", ref paientInfo, ref PrenoList);
            if (retint != 0)
            {
                return;
            }

            string[] split = PrenoList[0].ToString().Split('^')[2].Split('|');
            //371100287582|3711004348|371121200608092328|马芮|2|01|20060809000000||||80||||||五莲县高泽镇中心小学|371121|96||61|0|2009|0|||||0|0|0|||0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|||0|||||||||||||371121|
            string birthdaystr = "1900-01-01";
            try
            {
                //19400827
                //Convert.ToDateTime(split[39].Substring(0, 4) + "-" + split[39].Substring(4, 2) + "-" + split[39].Substring(6, 2));
                birthdaystr = split[6].Substring(0, 4) + "-" + split[6].Substring(4, 2) + "-" + split[6].Substring(6, 2);
                //birthdaystr = split[7];                 //生日返回的格式 1900-01-01
            }
            catch (Exception)
            {
                birthdaystr = "1900-01-01";
            }

            txtXm.Text = split[3];
            txtXB.Text = (split[4].Equals("1")) ? "男" : "女";
            txtSR.Text = birthdaystr;

            txtNl.Text = Convert.ToString(System.DateTime.Today.Year - Convert.ToDateTime(birthdaystr).Year);
            txtYbh.Text = split[0];
            txtKh.Text = split[9];//卡号
            txtSfzh.Text = split[2];
            txtAreaCode.Text = split[17];//所属区号
            txtPersonType.Text = GetPersonType(split[10]);
            txtInhosState.Text = (split[34] == "1") ? "住院" : "出院";

            #region 增加银行卡读卡获取卡余额
            PosChantEnity entity = new PosChantEnity();
            entity.MerchanCode = "03";
            entity.MerchanMoney = "";
            entity.POSFlowNo = DateTime.Now.ToString("MMddss");
            entity.CashMemberNo = "";
            entity.CashRegNo = "";
            entity.OrginTerminalNo = "";
            entity.AuthorizationNo = "";
            entity.OrginTranDT = "";
            entity.TerminalType = "7";
            txtYE.Text = medicare.ShowBalance(entity);
            #endregion


        }


        private void dataBlind()
        {
            ybbzFacade = new YBBZInfoFacade();
            DataSet ds = ybbzFacade.FindAll();
            lookUpEditEx1.Table = ds.Tables[0];
        }

        private void lookUpEditEx1_QueryCloseUp(object sender, CancelEventArgs e)
        {
            if (null == lookUpEditEx1.SelectedRow)
            {

                return;

            }
            DataRow row = lookUpEditEx1.SelectedRow;
            bzbm = row["JBBM"].ToString();
            bzmc = row["JBMC"].ToString();
        }


    }
}
